<template>
  <div class="main-layout">
    <div class="header">
      <div class="left">
        <div class="logo f14">小程音乐盒！</div>
        <div class="nav">
          <el-icon @click="$router.go(-1)">
            <ArrowLeft />
          </el-icon>
          <el-icon @click="$router.go(-1)">
            <ArrowRight />
          </el-icon>
        </div>
        <div class="search">
          <el-input prefix-icon="Search" v-model="keywords" @keyup.enter="handleSearch" :placeholder="placeholder"/>
        </div>
      </div>
      <div class="right">
        <UserInfo v-if="userStore.isShowUserInfo" />
        <div v-else class="flex1">
          <el-avatar class="mr10" shape="square" :size="30" />
          <p class="mr10 f14">未登录</p>
        </div>
        <el-switch inline-prompt size="large" inactive-icon="Moon" active-icon="Sunny" v-model="isDark" @change="toggleDark"></el-switch>
      </div>
    </div>
    <div class="center">
      <div class="aside">
        <el-scrollbar>
          <Aside />
        </el-scrollbar>
      </div>
      <el-scrollbar class="main p20">
        <router-view></router-view>
      </el-scrollbar>
    </div>
    <div class="footer">
      <Player/>
    </div>
  </div>
</template>

<script setup>
import {computed,ref,onMounted,getCurrentInstance} from 'vue'
import Aside from '../components/Aside.vue'
import Player from '@/components/Player.vue'
import UserInfo from '../components/UserInfo.vue'
import { useDark, useToggle } from '@vueuse/core'
import { useUserStore } from '@/store/userInfo'
import {useMusicStore} from '@/store/music.js'
import {useRouter} from 'vue-router'
const router=useRouter()
const musicStore=useMusicStore()
const userStore = useUserStore()
const isDark = useDark()
const {proxy}=getCurrentInstance()
// 暗黑模式切换事件
const toggleDark = ()=>{
  useToggle(isDark)
  userStore.setDark(isDark.value)
}
const url=computed(()=>{
  return musicStore.curPlayMusicUrl
})
let keywords=ref('')
let handleSearch=()=>{
  router.push({path:'/result'})
  if(keywords.value==''){
    keywords.value=placeholder.value
  }
  userStore.searchResult(keywords.value)
}
let placeholder=ref('')
let getSearchDefault=async()=>{
  let {data}=await proxy.$api.getSearchDefault()
  placeholder.value=data.realkeyword
}
onMounted(async() => {
  await getSearchDefault()
  userStore.setDark(isDark.value)
})

</script>

<style lang="scss">
$border-color: rgba(
  $color: rgb(102, 76, 76),
  $alpha: 0.4,
);
.main-layout {
  height: 100%;
  display: flex;
  flex-direction: column;
  .header {
    width: 100%;
    min-width: 1385px;
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid $border-color;
    .left {
      width: 600px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .logo {
        width: 150px;
        text-align: center;
      }
      .nav {
        width: 100px;
        .el-icon:hover {
          color: #18a058;
        }
      }
      .search {
        width: 300px;
      }
    }
    .right {
      width: 300px;
      display: flex;
      justify-content: space-around;
      align-items: center;
    }
  }
  .center {
    height: calc(100% - 122px);
    min-height: 600px;
    display: flex;
    .aside {
      height: 100%;
      width: 220px;
      border-right: 1px solid $border-color;
    }
    .main {
      height: 100%;
      width: calc(100% - 161px);
      min-width: 1200px;
    }
  }
  .footer {
    border-top: 1px solid $border-color;
    width: 100%;
    height: 70px;
    min-width: 1385px;
  }
}
</style>
